package net.nshc.kwkim.mycalc.util;

import net.nshc.kwkim.mycalc.buttonlistener.*;

public class ButtonContentAnalyzer {

	public static boolean isTheLastCharacterNumber(String str) {
    	str = EqualSignButtonClickListener.changeExtendexp(str);
        if ((str == null) || (str.length() < 1 || str.equals("")))
            return false;
        
        char c = str.charAt(str.length() - 1);

        return hasStringOnlyOneNumber(c);
    }
	
	private static boolean hasStringOnlyOneNumber(char c) {
		if ((c == '1') || (c == '2') || (c == '3') || (c == '4') ||
				(c == '5') || (c == '6') || (c == '7') || (c == '8') ||
				(c == '9') || (c == '0'))
			return true;

		return false;
	}

	public static boolean hasStringOnlyOneArithmeticOperator(String str) {
		if (str.equals("+") || str.equals("-") || str.equals("×") || str.equals("÷") || str.equals("sqrt") || str.equals("pow"))
				return true;

		return false;
	}

	public static boolean hasStringOnlyOneExtendArithmeticOperator(String str) {
		if ((str.equals("log")) || str.equals("ln") || str.equals("tan") || 
				str.equals("cos") || str.equals("sin") || str.equals("!") || 
				str.equals("nCm") || str.equals("|x|"))
			return true;

		return false;
	}
	
	public static String hasStingErrorMessage(String str){
		
		if(str.contains("error"))
			return str.replace("error", "");
		if(str.contains("Denominator is 0"))
			return str.replace("Denominator is 0", "");
		return str;
	}

}